import type { IFieldProps, IConfigProps } from '@/components/sofastui/AdvancedTable/interface'
import type { FormRule } from '@form-create/element-ui'
import { defaultRoutes } from '@/router/routes'

export const fields: IFieldProps[] = [
  {
    label: '图标',
    prop: 'icon',
    width: 60,
    align: 'center',
    import: true,
    export: true,
    slot: true,
  },
  {
    label: '标题',
    prop: 'title',
    minWidth: 60,
    import: true,
    export: true,
  },
  {
    label: '组件名称',
    prop: 'name',
    minWidth: 60,
    import: true,
    export: true,
  },
  {
    label: '菜单路径/权限标识',
    prop: 'value',
    width: 200,
    import: true,
    export: true,
    slot: true,
  },
  {
    label: '排序',
    prop: 'orderNum',
    width: 80,
    align: 'center',
    import: true,
    export: true,
  },
  {
    label: '类型',
    prop: 'type',
    width: 100,
    align: 'center',
    import: true,
    export: true,
    type: 'radio',
    isTag: true,
    filter: true,
    options: [
      {
        value: 1,
        label: '菜单',
      },
      {
        value: 2,
        label: '按钮',
      },
    ],
  },
  {
    label: '启用',
    prop: 'enabled',
    width: 100,
    align: 'center',
    import: true,
    export: true,
    slot: true,
  },
  {
    label: '显示',
    prop: 'display',
    width: 100,
    align: 'center',
    import: true,
    export: true,
    slot: true,
  },
]

export const config: IConfigProps = {
  name: 'powMenuTable',
  rowKey: 'id',
  url: '/api/idt/menu',
  selection: true,
  add: true,
  delete: true,
  expand: true,
  showIndex: true,
  import: true,
  export: true,
  search: true,
  advancedSearch: true,
  refresh: true,
  settings: true,
}

export const formRules: FormRule = [
  {
    type: 'cascader',
    field: 'parentId',
    title: '上级菜单',
    effect: {
      fetch: {
        action: '/api/idt/menu/tree',
        method: 'GET',
        dataType: 'json',
        headers: {},
        query: {},
        data: {},
        parse: '',
        beforeFetch: '',
        onError: '',
        to: 'props.options',
      },
    },
    $required: false,
    props: {
      _optionType: 3,
      props: {
        multiple: false,
        checkStrictly: true,
        emitPath: false,
        value: 'id',
        label: 'title',
        children: 'children',
        disabled: 'disabled',
      },
      filterable: true,
    },
    _fc_id: 'id_Fjc6mc4x5d2xc8c',
    name: 'parentId',
    _fc_drag_tag: 'cascader',
    col: {
      span: 12,
    },
    style: {
      width: '100%',
    },
    display: true,
    hidden: false,
  },
  {
    type: 'radio',
    field: 'type',
    title: '类型',
    effect: {
      fetch: '',
    },
    $required: true,
    props: {
      type: 'default',
      input: false,
    },
    value: 1,
    options: [
      {
        label: '菜单',
        value: 1,
      },
      {
        label: '按钮',
        value: 2,
      },
    ],
    _fc_id: 'id_Ftlcmc4wyz4rb4c',
    name: 'type',
    _fc_drag_tag: 'radio',
    col: {
      span: 12,
    },
    display: true,
    hidden: false,
  },
  {
    type: 'input',
    field: 'title',
    title: '标题',
    $required: true,
    _fc_id: 'id_Frwqmc4w6t1oadc',
    name: 'title',
    _fc_drag_tag: 'input',
    col: {
      span: 12,
    },
    display: true,
    hidden: false,
  },
  {
    type: 'select',
    field: 'name',
    title: '页面组件',
    effect: {
      fetch: '',
    },
    $required: true,
    options: Array.from(defaultRoutes.keys()).map((item) => ({
      label: item,
      value: item,
    })),
    _fc_id: 'id_Fm9emc4x3yzfbkc',
    name: 'name',
    _fc_drag_tag: 'select',
    col: {
      span: 12,
    },
    display: true,
    hidden: false,
    props: {
      filterable: true,
    },
    computed: {
      hidden: {
        mode: 'AND',
        group: [
          {
            field: 'type',
            condition: '==',
            value: 1,
          },
        ],
        invert: true,
      },
    },
  },
  {
    type: 'input',
    field: 'path',
    title: '访问Url',
    $required: true,
    _fc_id: 'id_Fgq5mc4xpzhuc7c',
    name: 'path',
    display: true,
    hidden: false,
    _fc_drag_tag: 'input',
    col: {
      span: 12,
    },
    computed: {
      hidden: {
        mode: 'AND',
        group: [
          {
            field: 'type',
            condition: '==',
            value: 1,
          },
        ],
        invert: true,
      },
    },
  },
  {
    type: 'cascader',
    field: 'redirect',
    title: '重定向',
    effect: {
      fetch: {
        action: '/api/idt/menu/tree',
        method: 'GET',
        dataType: 'json',
        headers: {},
        query: {},
        data: {},
        parse: '',
        beforeFetch: '',
        onError: '',
        to: 'props.options',
      },
    },
    $required: false,
    props: {
      _optionType: 3,
      props: {
        multiple: false,
        checkStrictly: true,
        emitPath: false,
        value: 'value',
        label: 'title',
        children: 'children',
        disabled: 'disabled',
      },
      filterable: true,
    },
    _fc_id: 'id_Fkfdmc4wxoczauc',
    name: 'redirect',
    _fc_drag_tag: 'cascader',
    col: {
      span: 12,
    },
    style: {
      width: '100%',
    },
    display: true,
    hidden: false,
    computed: {
      hidden: {
        mode: 'AND',
        group: [
          {
            field: 'type',
            condition: '==',
            value: 1,
          },
        ],
        invert: true,
      },
    },
  },
  {
    type: 'input',
    field: 'value',
    title: '权限标识',
    $required: true,
    _fc_id: 'id_F1limc4xbv1nd6c',
    name: 'value',
    _fc_drag_tag: 'input',
    col: {
      span: 12,
    },
    display: true,
    hidden: false,
    computed: {
      hidden: {
        mode: 'AND',
        group: [
          {
            field: 'type',
            condition: '==',
            value: 2,
          },
        ],
        invert: true,
      },
    },
  },
  {
    type: 'input',
    field: 'icon',
    title: '图标',
    $required: false,
    _fc_id: 'id_Fufsmc4x4kshbtc',
    name: 'icon',
    _fc_drag_tag: 'input',
    col: {
      span: 12,
    },
    display: true,
    hidden: false,
  },
  {
    type: 'inputNumber',
    field: 'orderNum',
    title: '排序值',
    $required: true,
    _fc_id: 'id_Fw46mc4xjwt6eac',
    name: 'orderNum',
    _fc_drag_tag: 'inputNumber',
    col: {
      span: 12,
    },
    props: {
      controlsPosition: 'right',
    },
    value: 1,
    style: {
      width: '100%',
    },
    display: true,
    hidden: false,
  },
  {
    type: 'input',
    field: 'desc',
    title: '描述',
    $required: false,
    _fc_id: 'id_Favymc4y2pyedic',
    name: 'desc',
    display: true,
    hidden: false,
    _fc_drag_tag: 'input',
    col: {
      span: 12,
    },
  },
  {
    type: 'switch',
    field: 'enabled',
    title: '启用',
    $required: false,
    props: {
      activeValue: 1,
      inactiveValue: 0,
    },
    value: 1,
    _fc_id: 'id_Fzdwmc4xxxorcyc',
    name: 'enabled',
    display: true,
    hidden: false,
    _fc_drag_tag: 'switch',
    col: {
      span: 3,
    },
  },
  {
    type: 'switch',
    field: 'display',
    title: '显示',
    $required: false,
    props: {
      activeValue: 1,
      inactiveValue: 0,
    },
    value: 1,
    _fc_id: 'id_F2grmc4xyhrbd3c',
    name: 'display',
    _fc_drag_tag: 'switch',
    display: true,
    hidden: false,
    col: {
      span: 3,
    },
    computed: {
      hidden: {
        mode: 'AND',
        group: [
          {
            field: 'type',
            condition: '==',
            value: 1,
          },
        ],
        invert: true,
      },
    },
  },
  {
    type: 'switch',
    field: 'isLeaf',
    title: '末级',
    $required: false,
    props: {
      activeValue: 1,
      inactiveValue: 0,
    },
    value: 0,
    _fc_id: 'id_Fm5bmc4xyqtbd8c',
    name: 'isLeaf',
    _fc_drag_tag: 'switch',
    display: true,
    hidden: false,
    col: {
      span: 3,
    },
    computed: {
      hidden: {
        mode: 'AND',
        group: [
          {
            field: 'type',
            condition: '==',
            value: 1,
          },
        ],
        invert: true,
      },
    },
  },
  {
    type: 'switch',
    field: 'keepAlive',
    title: '缓存',
    $required: false,
    props: {
      activeValue: 1,
      inactiveValue: 0,
    },
    value: 0,
    _fc_id: 'id_Fvf6mc4xyzlrddc',
    name: 'keepAlive',
    _fc_drag_tag: 'switch',
    display: true,
    hidden: false,
    col: {
      span: 3,
    },
    computed: {
      hidden: {
        mode: 'AND',
        group: [
          {
            field: 'type',
            condition: '==',
            value: 1,
          },
        ],
        invert: true,
      },
    },
  },
]
